<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Title</title>
</head>
<body>
<h2>当前计数：<span class="counter"></span></h2>
<button class="add">+1</button>
<button class="sub">-1</button>
<script>
    const h2El=document.querySelector("h2")
    const counterEl=document.querySelector(".counter")
    const addBtnEl=document.querySelector(".add")
    const subBtnEl=document.querySelector(".sub")

    let counter=100
    counterEl.textContent=counter

    addBtnEl.onclick=function(){
        counter++
        counterEl.textContent=counter
    }

    subBtnEl.onclick=function(){
        counter--
        counterEl.textContent=counter
    }
</script>
</body>
</html>